<?php

/**
 * 
 */
class Myprofile extends CI_Controller {

    var $area = 0;
    var $keywords = 0;

    function __construct() {
        parent::__construct();
        $this->load->library('googlemaps');
        $this->load->model('areas_model');
        $this->load->model('users_model');
        $this->load->model('reports_model');
    }

    public function index() {
        $user_id = $this->session->userdata("sess_user_id");

        $config['center'] = '48.75,19.70';
        $config['map_height'] = 450;
        $config['sensor'] = false;
        $config['map_width'] = 954;
        $config['zoom'] = '7';
        $this->googlemaps->initialize($config);
        $data['map'] = $this->googlemaps->create_map();

        if ($user_id = $this->session->userdata("sess_user_id")) {
            $content['kk'] = $this->areas_model->returnAllAreas();
            $user_areas = $this->users_model->checkUserAreas($user_id);
            foreach ($content['kk'] as $key => $value) {
                $plus = $this->area++;
                if (strstr($user_areas['areas'], $value['area_id'])) {
                    $content['div'][$plus] = "<div style='margin-right: 25px;' class='checkbox_route_left checkbox_route_checked' id='area_" . $value['area_id'] . "'>" . $value['name'] . "</div>";
                } else {
                    $content['div'][$plus] = "<div style='margin-right: 25px;' class='checkbox_route_left' id='area_" . $value['area_id'] . "'>" . $value['name'] . "</div>";
                }
            }

            // keywords
            $user_keywords = $this->users_model->checkUserKeywords($user_id);
            $user_keywords_array = explode(',', $user_keywords['keywords']);
            foreach ($user_keywords_array as $key) {
                if ($key != null) { // na zaciatu ma kazdy null...
                    $plus = $this->keywords++;
                    $arr = $this->reports_model->checkOccurences($key);
                    $content['keywords'][$plus] = "<div class='keyword'><div class='close_img'></div>" . $key . "<span> (" . $arr['pocet'] . ")</span></div>";
                }
            }
            $this->load->view('templates/header', $data);
            $this->load->view('profile/profile', $content);
            $this->load->view('templates/footer');
        }
    }

}

?>